package openadmin.model.territory;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import openadmin.dao.Base;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

@Entity
@Table(name = "street", schema = "territory", uniqueConstraints = {@UniqueConstraint(columnNames ="description"),@UniqueConstraint(columnNames =  {"municipality","codestreet", "streetName"})})
public class Street implements Base, java.io.Serializable{

	/** attribute that contains the identifier*/
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)	
	private Integer id;

	/** attribute that contains the code Street*/	
	@NotNull
	private Integer codestreet;
				
	/** attribute that contains the street name, not unique value*/
	@Length(max = 60)
	@NotNull
	private String streetName;
	
	/** attribute that contains the streetName, unique value*/
	@Length(max = 60)
	@NotNull
	private String description;
	
	/** Transient attribute that means that the system should make a log on any JPA operation of this class*/
	@Transient
	private boolean debuglog = true;
	
	/** Transient attribute that means that the system should make a historic on any JPA operation of this class*/
	@Transient
	boolean historiclog = true;
	
	/** attribute that contains the relationship with Municipality*/
	@ManyToOne
	@JoinColumn(name = "municipality", nullable= false)
	private Municipality municipality;
	
	/** attribute that contains the relationship with type of Street*/
	@ManyToOne
	@JoinColumn(name = "typestreet", nullable= false)
	private TypeStreet typestreet;		

	/**
	 * Constructor of the class Street.
	 * without parameters
	 */
	public Street() { 
		
	}
	
	/**
	 * Constructor of the class Street.
	 * @param pDescription, is the description, (unique value), of the Street
	 */
	public Street(String pDescription) {
		
		this.description = pDescription.toUpperCase();
		
	}
	
	/** Getters and setters*/
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getCodeStreet() {
		return codestreet;
	}

	public void setCodeStreet(Integer codeStreet) {
		this.codestreet = codeStreet;
	}

	public String getStreetName() {
		return streetName;
	}

	public void setStreetName(String streetName) {
		this.streetName = streetName.toUpperCase();
	}
	public String getDescription() {
		return description;
	}
	
	/* in order to get a unique description */
	public void setDescription() {
		this.description = streetName+"."+Integer.toString(this.municipality.getCodemunicipalitydgc());
	}

	public boolean getDebugLog() {
		
		return debuglog;
	}
	
	public void setDebugLog(boolean pDebuglog) {
		
		debuglog = pDebuglog;
	
	}
	
	public Municipality getMunicipality() {
		return municipality;
	}

	public void setMunicipality(Municipality municipality) {
		this.municipality = municipality;
	}

	public TypeStreet getTypeStreet() {
		return typestreet;
	}

	public void setTypeStreet(TypeStreet typeStreet) {
		this.typestreet = typeStreet;
	}
	
	public boolean getHistoricLog() {
		return historiclog;
	}

	public void setHistoricLog(boolean historiclog) {
		this.historiclog = historiclog;
	}
		
	@Override
	public String toString(){
		 
		 return description;
	}
	
}
